package com.hong.spring.ioc;


import com.hong.spring.common.entity.User;
import com.hong.spring.common.entity.User2;
import com.hong.spring.common.service.MessageService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;

/**
 * @Auther: csh
 * @Date: 2020/7/7 11:44
 * @Description:
 */
public class IocTest {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationfile*.xml");
        System.out.println("context 已启动!");
        //setter实现
        User user = context.getBean(User.class,"user.properties");
        System.out.println("user信息："+user.toString());
        System.out.println("是否一致!"+context.isTypeMatch("user.properties",User.class));
        Class <?> user1 = context.getType("user.properties");
        System.out.println(user1.toString());
        System.out.println(Arrays.asList(context.getAliases("user.properties")).toString());

        //构造方法获取
        User2 user2 = context.getBean(User2.class, "user2");
        System.out.println("user信息："+user2.toString());
        //自动注解方式
        MessageService service = context.getBean(MessageService.class);
        //打印service的信息
        System.out.println(service.getMessage());
    }

}
